/*
2021-7-23
https://www.acwing.com/problem/content/177/
*/
#include<cstring>
#include<iostream>
#include<algorithm>
#include<deque>

using namespace std;
typedef pair<int,int>PII;
const int N=505;
char g[N][N];
int dist[N][N];
bool st[N][N];
int n,m;

int bfs()
{
    memset(dist,0x3f,sizeof dist);
    memset(st,0,sizeof st);
    dist[0][0]=0;
    deque<PII> q;
    q.push_back({0,0});
    
    int dx[]={-1,-1,1,1},dy[]={-1,1,1,-1};
    int ix[]={-1,-1,0,0},iy[]={-1,0,0,-1};
    char cs[]="\\/\\/";
    
    while(q.size())
    {
        auto t=q.front();
        q.pop_front();
        
        if(st[t.first][t.second]) continue;
        st[t.first][t.second]=true;
        
        for(int i=0;i<4;i++)
        {
            int a=t.first+dx[i],b=t.second+dy[i];
            if(a<0 || a>n || b<0 || b>m) continue;
            
            int gx=t.first+ix[i],gy=t.second+iy[i];
            int d=dist[t.first][t.second]+(cs[i]!=g[gx][gy]);
            
            if(dist[a][b]>d)
            {
                dist[a][b]=d;
                if(cs[i]!=g[gx][gy]) q.push_back({a,b});
                else q.push_front({a,b});
            }
            
        }
        
    }
    return dist[n][m];
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n>>m;
        for(int i=0;i<n;i++) cin>>g[i];
        
        int t=bfs();
        
        if(t==0x3f3f3f3f) puts("NO SOLUTION");
        else cout<<t<<endl;
    }
    return 0;
}

